package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    @PostMapping("reg")
    public JsonResult reg(VehicleSaveParam vehicleSaveParam){
        log.debug("新增车辆业务: vehicleSaveParam={}",vehicleSaveParam);
        vehicleService.reg(vehicleSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(VehicleQuery vehicleQuery){
        log.debug("查询车辆业务:vehicleQuery={}",vehicleQuery);
        List<VehicleVO> vehicleVOS = vehicleService.select(vehicleQuery);
        return JsonResult.ok(vehicleVOS);
    }
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("车辆删除业务:id={}",id);
        vehicleService.delete(id);
        return JsonResult.ok();
    }
    @PostMapping("unbind/{id}")
    public JsonResult unbind(@PathVariable Long id){
        log.debug("解绑业务:id={}",id);
        vehicleService.unbind(id);
        return JsonResult.ok();
    }
    @PostMapping("bind/{id}/{geoId}")
    public JsonResult bind(@PathVariable Long id,@PathVariable Long geoId){
        log.debug("绑定业务:id={},geoId={}",id,geoId);
        vehicleService.bind(id,geoId);
        return JsonResult.ok();
    }
}
